const log4js = require('../../../utils/log4js');
const smsServices = require('../../../services/dao/common/sms');

const $ = module.exports;

// 生成短信验证码
$.get_create = async (req, res) => {
    let {mobile} = req.query;
    smsServices.crate(mobile).then((data) => {
        res.jsonWrap(data);
    }).catch((e) => {
        log4js.error(e);
        if(e.code ==='isv.BUSINESS_LIMIT_CONTROL') {
            res.jsonWrap(null, 1, e.data.Message);
        } else {
            res.jsonWrap(null, 1, e.message);
        }
    });
};

// 验证短信验证码
$.get_check = async (req, res) => {
    let {mobile, code} = req.query;
    smsServices.check(mobile, code).then((data) => {
        res.jsonWrap(data);
    }).catch((e) => {
        log4js.error(e);
        res.jsonWrap(null, 1, e.message);
    });
};



